/**
 * Created By wifi_uncle on 2020/2/12
 */

import Utils from '../utils'
import { SUCCESS_CODE } from '../constant'
export default ({url = '',  body,  errorMsg = '操作失败', _this, method="post", showErrorMsg = true }) => {
  return _this.$http[method](url, body).then(rsp => {
    const data = rsp.body
    if (data && data.result === SUCCESS_CODE) {
      return Promise.resolve(data)
    } else {
      if(showErrorMsg) {
        Utils.showFailMsg(errorMsg)
      }
      return Promise.reject(data)
    }
  }, e => {
    if(showErrorMsg) {
      Utils.showFailMsg(errorMsg)
    }
    return Promise.reject(e)
  })
}

